package com.mjk.manager.api.dto;

import java.io.Serializable;
import java.util.List;

import com.mjk.manager.amis.core.model.SysMenu;
import com.mjk.manager.api.constns.ApiPostProperties;
import lombok.Data;

/**
 * 
 * @author Administrator
 *
 */
@Data
public class ApiPostRequest implements Serializable{
	public ApiPostRequest() {
		this.request = new Request();
		this.response = new Response();
	}
	/**
	 * 创建目录结构
     */
	public ApiPostRequest(SysMenu menu, ApiPostProperties properties) {
		
		this.target_id = menu.getApipostMenuId();
		this.parent_id = menu.getPID();
		this.project_id = properties.getProjectId();
		this.target_type = "folder";
		this.name = menu.getNAME();
		this.request = new Request();	
		this.response = new Response();
	}

	/**
	 * 接口ID
	 */
	private String target_id;
	/**
	 * 	项目ID
	 */
	private String project_id;
	/**
	 * 	父目录ID 根目录为"0"
	 */
	private String parent_id;
	/**
	 * 	接口完成状态。开发中：developing（默认）、已完成：complated、需修改：modifying
	 */
	private String mark="developing";
	/**
	 * 	节点类型 api-接口 doc-文档 folder-目录 websocket grpc
	 */
	private String target_type="api";
	/**
	 * 	接口名称
	 */
	private String name;
	/**
	 * 	排序
	 */
	private String sort;
	/**
	 * 	请求
	 */
	private Request request;
	
	/**
	 * 	返回
	 */
	private Response response;
	
	@Data
	public static class Request{
		public Request() {
			this.auth = new Auth();
			this.event = new Event();
		}
		/**
		 * 接口url
		 */
		private String url;
		/**
		 * 接口说明
		 */
		private String description;
		
		private Auth auth;
		
		private Body body;
		
		private Event event;
		
		private Query query;
	}
	
	@Data
	public static class Auth{
		public Auth() {
			this.type="noauth";
			this.bearer = new Bearer();
			this.basic = new Basic();
			this.kv = new KV();
		}
		private String type;
		private KV kv;
		private Bearer bearer;
		private Basic basic;
	}
	@Data
	public static class KV{
		private String key="";
		private String value="";
	}
	@Data
	public static class Bearer{
		private String key="";
	}
	@Data
	public static class Basic{
		private String username="";
		private String password="";
	}
	@Data
	public static class Body{
		public Body(){
			this.mode = "json";
		}
		private String mode;
		private List<Parameter> parameter;
		private String raw;
		private String raw_para;
		
	}
	@Data
	public static class Event{
		public Event() {
			this.pre_script="apt.environment.set(\"key\", \"value\");";
			this.test="apt.assert('response.raw.type==\"json\"');";
		}
		private String pre_script;
		private String test;
	}
	@Data
	public static class Header{
		private  List<Parameter> parameter;
	}
	@Data
	public static class Parameter{
		private String description;
		private String is_checked;
		private String key;
		private String type;
		private String not_null;
		private String field_type;
		private String value;
	}
	@Data
	public static class Query{
		private List<Parameter> parameter;
	}
	/**
	 * 响应体
	 * @author Administrator
	 *
	 */
	@Data
	public static class Response{
		private Success success;
		private Error error;
	}
	@Data
	public static class Success{
		public Success(){}
		public Success(List<Parameter> parameters){
			this.raw="{}";
			this.parameter = parameters;
		}
		private String raw;
		private List<Parameter> parameter;
	}
	@Data
	public static class Error{
		private String raw;
		private List<Parameter> parameter;
	}
	@Data
	public static class Expect{
		private String name;
		private String isDefault;
		private String code;
		private String contentType;
		private String verifyType;
		//private String schema;
		private String mock;
	}
	

}

